<%
'#################################################################################
'## UnWritten Open Source Blog Engine
'#################################################################################
'## Copyright (C) 2008 Luigi Violin
'##
'## This program is free software: you can redistribute it and/or modify
'## it under the terms of the GNU General Public License as published by
'## the Free Software Foundation, either version 2 of the License, or
'## (at your option) any later version.
'##
'## This program is distributed in the hope that it will be useful,
'## but WITHOUT ANY WARRANTY; without even the implied warranty of
'## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'## GNU General Public License for more details.
'##
'## You should have received a copy of the GNU General Public License
'## along with this program.  If not, see <http://www.gnu.org/licenses/>.
'##
'## You can obtain support from our forums at:
'##     <http://www.unwrittenblog.com/forums/>
'## Contact the author directly:
'##     <zaamit@hotmail.com/>
'##
'#################################################################################
%>
<%
page_name = ""
page_action = "list-contents"
cat = request.QueryString("cat")
%>

<!--#include virtual="/default.asp"-->

<%
function listContents
  Dim currcat
  if cat = "" then
  	listContents = "<h1>By category</h1>"
	listContents = listContents & "<ul>"
	dbRS2.open "select count(id) as numart,category from " & db_prefix & "posts where ent_type = 2 and ent_name not in ('about','contact','home') and publish_status = 1 group by category",dbConn
	if dbRS2.eof then
		listContents = listContents & "No categories found."
	end if
	do while not dbRS2.eof
		currcat = dbRS2("category")
		if isnull(currcat) then currcat = "Uncategorized"
		listContents = listContents & "<li><a href=""/contents.asp?cat=" & currcat & """>" & currcat & "</a> (" & dbRS2("numart") & ") </li>"
		dbRS2.movenext
	loop
	listContents = listContents & "</ul>"
	listContents = listContents & "<h1>Most recent</h1>"
	dbRS2.close
	listContents = listContents & "<ul>"
	dbRS2.open "select ent_name,title from " & db_prefix & "posts where ent_type = 2 and ent_name not in ('about','contact','home') and publish_status = 1 order by pdate limit 5",dbConn
	  	if dbRS2.eof then
			listContents = listContents & "No articles found."
		end if
	  do while not dbRS2.eof
		listContents = listContents & "<li><a href=""/?pg=" & dbRS2("ent_name") & """>" & dbRS2("title") & "</a></li>"
		dbRS2.movenext
	  loop
	  listContents = listContents & "</ul>"
	else
		if cat = "Uncategorized" then
			cat = ""
			sqlcat = "isnull(category)"
			listContents = "<h1>Uncategorized articles</h1>"
			else
				listContents = "<h1>Articles categorized as <i>'" & cat & "'</i></h1>"
				sqlcat = "category = '" & cat & "'"
		end if
		listContents = listContents & "<ul>"
		dbRS2.open "select title,ent_name from " & db_prefix & "posts where ent_type = 2 and ent_name not in ('about','contact','home') and publish_status = 1 and " & sqlcat,dbConn
		do while not dbRS2.eof
			listContents = listContents & "<li><a href=""/?pg=" & dbRS2("ent_name") & """>" & dbRS2("title") & "</a></li>"
		dbRS2.movenext
		loop
	listContents = listContents & "</ul>"
  end if
  dbRS2.close
End function
%>